﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

using Microsoft.AspNetCore.Http;

namespace Microsoft.AspNetCore.Mvc
{
    public class EventStream
    {
        private readonly HttpResponse response;

        public EventStream(HttpResponse response)
        {
            this.response = response;
            response.ContentType = "text/event-stream";
        }

        public async Task WriteDataAsync(string data)
        {
            await response.WriteAsync($"data: {data}\r\r");
            await response.Body.FlushAsync();
        }

        public async Task EmitAsync(string @event, string data)
        {
            await response.WriteAsync($"{@event}: {data}\r\r");
            await response.Body.FlushAsync();
        }

     
    }
}
